﻿--[[
    @brief   ui logic for more_zone_tips
    @author  farleywen
    @version 1.0
    @date    2015/12/09
--]]


more_zone_tips_view = 
{
    tips_dialog = nil;
    tips_contents = nil;
    
    init = function()
    end;
    
    create = function()
        base_utility.log("[more_zone_tips_view] create");
        local dlg_id = layout_mgr.restore_layout("more_zone_tips.tpf");
        more_zone_tips_view.tips_dialog = ui_utility.get_ctrl_ptr_by_id(dlg_id);
        
        local uilib = ui_utility.uilib();
        if more_zone_tips_view.tips_dialog ~= nil then
            more_zone_tips_view.tips_dialog:Show(FALSE);
        end;
        
        local content_id = MainCommon.get_child_id(uilib, dlg_id, "txt_contents");
        local content_ptr = ui_utility.get_ctrl_ptr_by_id(content_id);
        if content_ptr ~= nil then
            more_zone_tips_view.tips_contents = tolua.cast(content_ptr, "Tenio::ITStatic");
        end;
    end;
        
    show = function()
        base_utility.log("[more_zone_tips_view] show");
        if more_zone_tips_view.tips_dialog == nil then
            more_zone_tips_view.create();
        end;
        if more_zone_tips_view.tips_dialog == nil then
            return;
        end;
        local pos = ierd_tgp.tray_ui.Point:new();
        base_utility.get_component_adapter("ITray_ui","ierd_tgp.tray_ui.get_Tray_ui_adapter()"):get_position_for_tips(pos);
        local rc = more_zone_tips_view.tips_dialog:GetRectEx(TRUE,TRUE);
        local x, y = pos.x+2, pos.y; -- wegame的托盘图标有左侧透明，相较TGP向右移2px
        pos:delete();
        more_zone_tips_view.show_tips(x, y);
    end;
    
    show_tips = function(x, y)
        base_utility.log("[more_zone_tips_view] show_tips");
        if more_zone_tips_view.tips_dialog == nil then
            more_zone_tips_view.create();
        end;
        if more_zone_tips_view.tips_dialog == nil then
            return;
        end;
        local str = more_zone_tips_model.content;
        local const_str, str_holder = U8toCUIStr(str);
        more_zone_tips_view.tips_contents:SetText(const_str);
        local rc = more_zone_tips_view.tips_dialog:GetRectEx(TRUE,TRUE);
        local width = rc.right - rc.left;
        local height = rc.bottom - rc.top;
        rc.left = x - width / 2;
        rc.right = x + width / 2;
        rc.top = y - height;
        rc.bottom = y;
        more_zone_tips_view.tips_dialog:MoveEx(rc,TRUE);
        more_zone_tips_view.tips_dialog:Show(TRUE);
    end;
        
    on_enter_new_zone = function()
    base_utility.log("[more_zone_tips_view] on_enter_new_zone");
        local game_id = more_zone_tips_model.game_id;
        if game_id ~= 0 then
            local game_lib =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
            
            if game_lib then
                game_lib:LaunchGameTcls(game_id);
            end;
        end
        more_zone_tips_view.close();
    end;
    
    close = function()
        base_utility.log("[more_zone_tips_view] close");
        if more_zone_tips_view.tips_dialog == nil then
            base_utility.log("[close]tips_dialog is nil.");
            return;
        end;
            
        more_zone_tips_view.tips_dialog:Show(FALSE);
        layout_mgr.delay_remove_ctrl(more_zone_tips_view.tips_dialog:GetControlID());
        more_zone_tips_view.tips_dialog = nil;
        base_utility.log("close success.");
    end;
};

more_zone_tips_view.init();